﻿namespace Lite.Messaging
{
    using System;

    /// <summary>
    /// A basic, generic implementation of the IParameter&lt;T&gt; interface.
    /// </summary>
    /// <typeparam name="T">
    /// The type of the values stored against this parameter.
    /// </typeparam>
    [Serializable]
    public partial struct Parameter<T>
    {
        /// <summary>
        /// Initializes a new instance of the Parameter struct.
        /// </summary>
        /// <param name="parameterId">
        /// The globally unique identifier for this parameter descriptor.
        /// </param>
        /// <param name="name">
        /// A user-readable description of this parameter descriptor.
        /// </param>
        public Parameter(Guid Id, string name)
            : this()
        {
            this.Id = Id;
            this.Name = name;
        }

        /// <summary>
        /// Indicates whether two parameters are equal.
        /// </summary>
        /// <param name="left">
        /// The first parameter to compare.
        /// </param>
        /// <param name="right">
        /// The second parameter to compare.
        /// </param>
        /// <returns>
        /// True if both parameters represent the same value; otherwise, False. 
        /// </returns>
        public static bool operator ==(Parameter<T> left, Parameter<T> right)
        {
            return left.Id == right.Id;
        }

        /// <summary>
        /// Indicates whether two parameters are not equal.
        /// </summary>
        /// <param name="left">
        /// The first parameter to compare.
        /// </param>
        /// <param name="right">
        /// The second parameter to compare.
        /// </param>
        /// <returns>
        /// True the parameters represent different values; otherwise, False. 
        /// </returns>
        public static bool operator !=(Parameter<T> left, Parameter<T> right)
        {
            return left.Id != right.Id;
        }

        /// <summary>
        /// Indicates whether this instance and another object are equal.
        /// </summary>
        /// <param name="obj">
        /// Another object against which to compare.
        /// </param>
        /// <returns>
        /// True if obj and this instance are the same type and represent the same value; otherwise, False. 
        /// </returns>
        public override bool Equals(object obj)
        {
            if (obj == null || !(obj is Parameter<T>))
            {
                return false;
            }

            return ((Parameter<T>)obj).Id == this.Id;
        }

        /// <summary>
        /// Returns the hash code for this instance.
        /// </summary>
        /// <returns>
        /// The hash code for this instance. 
        /// </returns>
        public override int GetHashCode()
        {
            return this.Id.GetHashCode();
        }
    }

    /// <content>
    /// The IParameter&lt;T&gt; members of the Parameter&lt;T&gt; class.
    /// </content>
    public partial struct Parameter<T>
            : IParameter<T>
    {
        /// <summary>
        /// Gets the globally unique identifier for this parameter descriptor.
        /// </summary>
        public Guid Id
        {
            get;
            private set;
        }

        /// <summary>
        /// Gets a user-readable description of this parameter descriptor.
        /// </summary>
        public string Name
        {
            get;
            private set;
        }

        /// <summary>
        /// Gets the default value for parameters of this type.
        /// </summary>
        public T DefaultValue
        {
            get;
            private set;
        }
    }
}